import {BasicColumn} from '/@/components/Table';
import {FormSchema} from '/@/components/Table';
import { rules} from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import {JVxeTypes,JVxeColumn} from '/@/components/jeecg/JVxeTable/types'
import { getWeekMonthQuarterYear } from '/@/utils';
//列表数据
export const columns: BasicColumn[] = [
   {
    title: '用户名',
    align:"center",
    dataIndex: 'username'
   },
   {
    title: '密码',
    align:"center",
    dataIndex: 'password'
   },
   {
    title: '性别',
    align:"center",
    dataIndex: 'sex_dictText'
   },
   {
    title: '年龄',
    align:"center",
    dataIndex: 'age'
   },
   {
    title: '生日',
    align:"center",
    dataIndex: 'birthday',
    customRender:({text}) =>{
      text = !text ? "" : (text.length > 10 ? text.substr(0,10) : text);
      return text;
    },
   },
   {
    title: '状态',
    align:"center",
    dataIndex: 'status',
    customRender:({text}) => {
       return  render.renderSwitch(text, [{text:'是',value:'Y'},{text:'否',value:'N'}])
     },
   },
   {
    title: '头像',
    align:"center",
    dataIndex: 'img',
    customRender:render.renderImage,
   },
   {
    title: '电话号码',
    align:"center",
    dataIndex: 'phone'
   },
   {
    title: '权限',
    align:"center",
    dataIndex: 'profession_dictText'
   },
   {
    title: '创建人',
    align:"center",
    sorter: true,
    dataIndex: 'createBy'
   },
   {
    title: '创建时间',
    align:"center",
    sorter: true,
    dataIndex: 'createTime'
   },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
     {
      label: "用户名",
      field: "username",
      component: 'Input', //TODO 范围查询
      //colProps: {span: 6},
	},
	{
      label: "性别",
      field: "sex",
      component: 'JDictSelectTag',
      componentProps:{
          dictCode:"sex"
      },
      //colProps: {span: 6},
 	},
	{
      label: "状态",
      field: "status",
      component: 'JSwitch',
      componentProps:{
           query:true,
       },
      //colProps: {span: 6},
 	},
	{
      label: "权限",
      field: "profession",
      component: 'JDictSelectTag',
      componentProps:{
          dictCode:"jurisdiction"
      },
      //colProps: {span: 6},
 	},
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '用户名',
    field: 'username',
    component: 'Input',
    dynamicRules: ({model,schema}) => {
          return [
                 { required: true, message: '请输入用户名!'},
          ];
     },
  },
  {
    label: '密码',
    field: 'password',
    component: 'Input',
    dynamicRules: ({model,schema}) => {
          return [
                 { required: true, message: '请输入密码!'},
          ];
     },
  },
  {
    label: '性别',
    field: 'sex',
    component: 'JDictSelectTag',
    componentProps:{
        dictCode:"sex"
     },
  },
  {
    label: '年龄',
    field: 'age',
    component: 'Input',
  },
  {
    label: '生日',
    field: 'birthday',
    component: 'DatePicker',
    componentProps:{
      valueFormat: 'YYYY-MM-DD'
    },    
  },
  {
    label: '状态',
    field: 'status',
    defaultValue: "0",
     component: 'JSwitch',
     componentProps:{
     },
    dynamicRules: ({model,schema}) => {
          return [
                 { required: true, message: '请输入状态!'},
          ];
     },
  },
  {
    label: '头像',
    field: 'img',
     component: 'JImageUpload',
     componentProps:{
        fileMax: 0
      },
  },
  {
    label: '电话号码',
    field: 'phone',
    component: 'Input',
    dynamicRules: ({model,schema}) => {
          return [
                 { required: true, message: '请输入电话号码!'},
          ];
     },
  },
  {
    label: '权限',
    field: 'profession',
    component: 'JDictSelectTag',
    componentProps:{
        dictCode:"jurisdiction"
     },
    dynamicRules: ({model,schema}) => {
          return [
                 { required: true, message: '请输入权限!'},
          ];
     },
  },
  {
    label: '创建人',
    field: 'createBy',
    component: 'Input',
    dynamicDisabled:true
  },
  {
    label: '创建时间',
    field: 'createTime',
    component: 'DatePicker',
    componentProps: {
       showTime:true,
       valueFormat: 'YYYY-MM-DD HH:mm:ss'
     },
    dynamicDisabled:true
  },
	// TODO 主键隐藏字段，目前写死为ID
	{
	  label: '',
	  field: 'id',
	  component: 'Input',
	  show: false
	},
];
//子表单数据
//子表表格配置
export const addressColumns: JVxeColumn[] = [
    {
      title: '联系方式',
      key: 'contact',
      type: JVxeTypes.input,
      width:"200px",
      placeholder: '请输入${title}',
      defaultValue:'',
    },
    {
      title: '收货人名字',
      key: 'receiver',
      type: JVxeTypes.input,
      width:"200px",
      placeholder: '请输入${title}',
      defaultValue:'',
    },
    {
      title: 'isdefault',
      key: 'isdefault',
      type: JVxeTypes.input,
      width:"200px",
      placeholder: '请输入${title}',
      defaultValue:'',
    },
    {
      title: 'isDelete',
      key: 'isDelete',
      type: JVxeTypes.input,
      width:"200px",
      placeholder: '请输入${title}',
      defaultValue:'',
    },
  ]


// 高级查询数据
export const superQuerySchema = {
  username: {title: '用户名',order: 0,view: 'text', type: 'string',},
  password: {title: '密码',order: 1,view: 'text', type: 'string',},
  sex: {title: '性别',order: 2,view: 'list', type: 'string',dictCode: 'sex',},
  age: {title: '年龄',order: 3,view: 'text', type: 'string',},
  birthday: {title: '生日',order: 4,view: 'date', type: 'string',},
  status: {title: '状态',order: 5,view: 'switch', type: 'string',},
  img: {title: '头像',order: 6,view: 'image', type: 'string',},
  phone: {title: '电话号码',order: 7,view: 'text', type: 'string',},
  profession: {title: '权限',order: 8,view: 'list', type: 'string',dictCode: 'jurisdiction',},
  createBy: {title: '创建人',order: 9,view: 'text', type: 'string',},
  createTime: {title: '创建时间',order: 10,view: 'datetime', type: 'string',},
  //子表高级查询
  address: {
    title: 'address',
    view: 'table',
    fields: {
        userId: {title: 'userId',order: 0,view: 'text', type: 'string',},
        contact: {title: '联系方式',order: 1,view: 'text', type: 'string',},
        receiver: {title: '收货人名字',order: 2,view: 'text', type: 'string',},
        isdefault: {title: 'isdefault',order: 3,view: 'text', type: 'string',},
        isDelete: {title: 'isDelete',order: 4,view: 'text', type: 'string',},
    }
  },
};

/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData): FormSchema[]{
// 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}